
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/26/2013 12:48:33
-- Generated from EDMX file: C:\Users\cbahr.CHCW\Desktop\MyProjects\WoTStats.Data\WoTStatsDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DB_63119_wotstats];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Players'
CREATE TABLE [dbo].[Players] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [WoTUniqueID] nvarchar(max)  NOT NULL,
    [ClanId] int  NOT NULL
);
GO

-- Creating table 'Clans'
CREATE TABLE [dbo].[Clans] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Tag] nvarchar(max)  NOT NULL,
    [WotUniqueID] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BattleResults'
CREATE TABLE [dbo].[BattleResults] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UniqueBattleID] nvarchar(max)  NOT NULL,
    [PlayerId] int  NOT NULL,
    [TankId] int  NOT NULL,
    [BattleDate] datetime  NOT NULL,
    [MapName] nvarchar(max)  NOT NULL,
    [Duration] int  NOT NULL,
    [FinishReason] int  NOT NULL,
    [AutoEquipGoldCost] int  NOT NULL,
    [AutoEquipCreditsCost] int  NOT NULL,
    [AutoLoadGoldCost] int  NOT NULL,
    [AutoLoadCreditsCost] int  NOT NULL,
    [AutoRepairCost] int  NOT NULL,
    [CapturePoints] int  NOT NULL,
    [Credits] int  NOT NULL,
    [CreditsPenalty] int  NOT NULL,
    [DailyXPFactor] int  NOT NULL,
    [DamageReceived] int  NOT NULL,
    [DroppedCapturePoints] int  NOT NULL,
    [EventCredits] int  NOT NULL,
    [EventFreeXP] int  NOT NULL,
    [EventGold] int  NOT NULL,
    [EventXP] int  NOT NULL,
    [FreeXP] int  NOT NULL,
    [Gold] nvarchar(max)  NOT NULL,
    [RemainingHealth] int  NOT NULL,
    [IsPremium] bit  NOT NULL,
    [IsTeamKiller] bit  NOT NULL,
    [LifeTime] int  NOT NULL,
    [Mileage] int  NOT NULL,
    [Shots] int  NOT NULL,
    [Team] int  NOT NULL,
    [TeamKills] int  NOT NULL,
    [CrewXP] int  NOT NULL,
    [Won] bit  NOT NULL,
    [XP] int  NOT NULL,
    [XPPenalty] int  NOT NULL
);
GO

-- Creating table 'BattleDamages'
CREATE TABLE [dbo].[BattleDamages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [BattleResultId] int  NOT NULL,
    [CriticalHits] int  NOT NULL,
    [AssistedDamage] int  NOT NULL,
    [DamageDealt] int  NOT NULL,
    [Fire] bit  NOT NULL,
    [HighExplosiveHits] int  NOT NULL,
    [Hits] int  NOT NULL,
    [Killed] bit  NOT NULL,
    [PiercedHits] int  NOT NULL,
    [Spotted] bit  NOT NULL,
    [TankId] int  NOT NULL
);
GO

-- Creating table 'Tanks'
CREATE TABLE [dbo].[Tanks] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UniqueID] int  NOT NULL,
    [Country] int  NOT NULL,
    [Type] int  NOT NULL,
    [Tier] int  NOT NULL,
    [Premium] bit  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ShortName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BattleEntries'
CREATE TABLE [dbo].[BattleEntries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UniqueBattleID] nvarchar(max)  NOT NULL,
    [PlayerId] int  NOT NULL,
    [BattleResult_Id] int  NOT NULL
);
GO

-- Creating table 'GarageSlots'
CREATE TABLE [dbo].[GarageSlots] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [GarageId] int  NOT NULL,
    [TankId] int  NOT NULL,
    [LastPlayed] datetime  NOT NULL,
    [BattleCount] int  NOT NULL,
    [BattleLifeTime] int  NOT NULL,
    [SurvivedBattles] int  NOT NULL,
    [Kills] int  NOT NULL,
    [MaxKills] int  NOT NULL,
    [Shots] nvarchar(max)  NOT NULL,
    [CapturePoints] int  NOT NULL,
    [DroppedCapturePoints] nvarchar(max)  NOT NULL,
    [DamageDealt] int  NOT NULL,
    [DamageReceived] nvarchar(max)  NOT NULL,
    [Wins] int  NOT NULL,
    [WinsAndSurvived] int  NOT NULL,
    [Losses] int  NOT NULL,
    [XP] int  NOT NULL,
    [TreesCut] int  NOT NULL,
    [Spotted] int  NOT NULL,
    [PlayerId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Players'
ALTER TABLE [dbo].[Players]
ADD CONSTRAINT [PK_Players]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Clans'
ALTER TABLE [dbo].[Clans]
ADD CONSTRAINT [PK_Clans]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BattleResults'
ALTER TABLE [dbo].[BattleResults]
ADD CONSTRAINT [PK_BattleResults]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BattleDamages'
ALTER TABLE [dbo].[BattleDamages]
ADD CONSTRAINT [PK_BattleDamages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tanks'
ALTER TABLE [dbo].[Tanks]
ADD CONSTRAINT [PK_Tanks]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BattleEntries'
ALTER TABLE [dbo].[BattleEntries]
ADD CONSTRAINT [PK_BattleEntries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'GarageSlots'
ALTER TABLE [dbo].[GarageSlots]
ADD CONSTRAINT [PK_GarageSlots]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ClanId] in table 'Players'
ALTER TABLE [dbo].[Players]
ADD CONSTRAINT [FK_PlayerClan]
    FOREIGN KEY ([ClanId])
    REFERENCES [dbo].[Clans]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlayerClan'
CREATE INDEX [IX_FK_PlayerClan]
ON [dbo].[Players]
    ([ClanId]);
GO

-- Creating foreign key on [BattleResultId] in table 'BattleDamages'
ALTER TABLE [dbo].[BattleDamages]
ADD CONSTRAINT [FK_BattleDamageBattleResult]
    FOREIGN KEY ([BattleResultId])
    REFERENCES [dbo].[BattleResults]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BattleDamageBattleResult'
CREATE INDEX [IX_FK_BattleDamageBattleResult]
ON [dbo].[BattleDamages]
    ([BattleResultId]);
GO

-- Creating foreign key on [BattleResult_Id] in table 'BattleEntries'
ALTER TABLE [dbo].[BattleEntries]
ADD CONSTRAINT [FK_BattleEntryBattleResult]
    FOREIGN KEY ([BattleResult_Id])
    REFERENCES [dbo].[BattleResults]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BattleEntryBattleResult'
CREATE INDEX [IX_FK_BattleEntryBattleResult]
ON [dbo].[BattleEntries]
    ([BattleResult_Id]);
GO

-- Creating foreign key on [PlayerId] in table 'BattleEntries'
ALTER TABLE [dbo].[BattleEntries]
ADD CONSTRAINT [FK_PlayerBattleEntry]
    FOREIGN KEY ([PlayerId])
    REFERENCES [dbo].[Players]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlayerBattleEntry'
CREATE INDEX [IX_FK_PlayerBattleEntry]
ON [dbo].[BattleEntries]
    ([PlayerId]);
GO

-- Creating foreign key on [TankId] in table 'BattleResults'
ALTER TABLE [dbo].[BattleResults]
ADD CONSTRAINT [FK_TankBattleResult]
    FOREIGN KEY ([TankId])
    REFERENCES [dbo].[Tanks]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TankBattleResult'
CREATE INDEX [IX_FK_TankBattleResult]
ON [dbo].[BattleResults]
    ([TankId]);
GO

-- Creating foreign key on [TankId] in table 'BattleDamages'
ALTER TABLE [dbo].[BattleDamages]
ADD CONSTRAINT [FK_TankBattleDamage]
    FOREIGN KEY ([TankId])
    REFERENCES [dbo].[Tanks]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TankBattleDamage'
CREATE INDEX [IX_FK_TankBattleDamage]
ON [dbo].[BattleDamages]
    ([TankId]);
GO

-- Creating foreign key on [TankId] in table 'GarageSlots'
ALTER TABLE [dbo].[GarageSlots]
ADD CONSTRAINT [FK_GarageSlotTank]
    FOREIGN KEY ([TankId])
    REFERENCES [dbo].[Tanks]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GarageSlotTank'
CREATE INDEX [IX_FK_GarageSlotTank]
ON [dbo].[GarageSlots]
    ([TankId]);
GO

-- Creating foreign key on [PlayerId] in table 'GarageSlots'
ALTER TABLE [dbo].[GarageSlots]
ADD CONSTRAINT [FK_PlayerGarageSlot]
    FOREIGN KEY ([PlayerId])
    REFERENCES [dbo].[Players]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlayerGarageSlot'
CREATE INDEX [IX_FK_PlayerGarageSlot]
ON [dbo].[GarageSlots]
    ([PlayerId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------